package cn.itheima.server_request;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//3.使用请求转发，servlet3向servlet4共享数据，并打印.
    @WebServlet("/ServletTest3")
    public class ServletTest3 extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           //设置共享数据
            request.setAttribute("encoding", "gbk");

            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/ServletTest4");//就这一个不需要写虚拟目录 别的都要写上
            requestDispatcher.forward(request, response);

        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    }

